package com.atguigu.gulimall.product.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Author baiWT
 * @Description
 * @Date 2022/4/4 19:45
 **/
@Configuration
public class MyThreadConfig {

    @Bean
    public ThreadPoolExecutor threadPoolExecutor(ThreadPoolConfigProperties pool){
        return new ThreadPoolExecutor(
                pool.getCoreSize(),//初始连接数
                pool.getMaxSize(),//最大连接数
                pool.getKeepAliveTime(),
                TimeUnit.SECONDS,//秒单位
                new LinkedBlockingDeque<>(100000),//线程等待数
                Executors.defaultThreadFactory(),//默认线程工厂
                new ThreadPoolExecutor.AbortPolicy());//默认丢弃处理
    }
}
